package com.bond.controller;

import com.bond.common.CommonResult;
import com.bond.common.ScanReq;
import com.bond.common.ScanResult;
import com.bond.service.SysService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class SysController {

    @Autowired
    private SysService sysService;

    /**
     * 扫码请求,这个请求地址需要配置到WiFiConfigure4.exe
     *
     * @return
     */
    @PostMapping("/api/dataupload")
    public ScanResult scanRequest(@RequestBody ScanReq scanReq) {
        ScanResult scanResult = new ScanResult();
        try {
            String err = sysService.insertScanReqInfo(scanReq);
            if (err != null) {
                scanResult.setPly(3);
                scanResult.setMsg(err);
            } else {
                scanResult.setPly(2);
            }
        } catch (Exception e) {
            log.error("扫码数据上传失败！设备id=" + scanReq.getId() + ",msg=" + scanReq.getMsg(), e);
            scanResult.setPly(3);
        }
        return scanResult;
    }


}
